const jwt = require('jsonwebtoken');
const db = require('../dataBase/db');

const jwtVerify = async(token) => {
    if (token) {
        try {
            let tokenDe = jwt.verify(token, 'NZY9');

            let res = await db.Users.findOne({ userId: tokenDe.userId });
            if (res.password == tokenDe.password) {
                return {
                    status: true,
                    conetnt: "token合法",
                    userData: res
                }
            } else {
                return {
                    status: false,
                    conetnt: "用户ID不存在"
                }
            }
        } catch (err) {
            console.log(err);
            return {
                status: false,
                content: "token不合法或已过期"
            }
        }
    } else {
        return {
            status: false,
            content: "token为空"
        }
    }
}
module.exports = jwtVerify;